﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Ex12.ReplaceHyperlinks
{
    class ReplaceHyperlinks
    {
        static void Main(string[] args)
        {
            string text = "Here is the link:<br>" +
            "<a href=http://www.telerik.com>Telerik</a><br>\n" +
            "and the logo:<a href=http://www.telerik.com>[IMG]\n" +
            "http://www.telerik.com/logo.png[/IMG]</a>\n";
            
            Console.WriteLine("Original:");
            Console.WriteLine(text);

            string searchPattern = @"<a href=(?<url>[^>]+)>" +
                @"(?<content>(.|\s)*?)</a>";
            string replacePattern = "[url href=\"${url}\"]${content}[/url]";


            string newText =
                Regex.Replace(text, searchPattern, replacePattern);
            Console.WriteLine("After replacing:");
            Console.WriteLine(newText);
        }
    }
}
